package com.huike.web.controller.report;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.huike.common.core.domain.AjaxResult;
import com.huike.report.service.IReportService;

import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import java.util.Date;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/index")
public class IndexController {

    @Autowired
    private IReportService reportService;


    /**
     * 首页--基础数据统计
     * @param beginCreateTime
     * @param endCreateTime
     * @return
     */
    @GetMapping("/getBaseInfo")
    public AjaxResult getBaseInfo(@RequestParam("beginCreateTime") String beginCreateTime,
                                  @RequestParam("endCreateTime") String endCreateTime){
        return AjaxResult.success(reportService.getBaseInfo(beginCreateTime,endCreateTime));
    }

    /**
     *功能描述:首页--今日简报
     *@return:
     */
    @GetMapping("/getTodayInfo")
    public AjaxResult getTodayInfo(){


        LocalDateTime today_start = LocalDateTime.of(LocalDate.now(), LocalTime.MIN);//当天零点
        String todayStartTime = today_start.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));

        LocalDateTime today_end = LocalDateTime.of(LocalDate.now(), LocalTime.MAX);//当天结束
        String todayEndTime = today_end.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));

        return AjaxResult.success(reportService.getTodayInfo(todayStartTime,todayEndTime));
    }

    /**
     *功能描述:首页--待办数据统计
     * @param beginCreateTime
     * @param endCreateTime
     *@return:
     */
    @GetMapping("/getTodoInfo")
    public AjaxResult getTodoInfo(@RequestParam("beginCreateTime") String beginCreateTime,
                                  @RequestParam("endCreateTime") String endCreateTime){

        return AjaxResult.success(reportService.getTodoInfo(beginCreateTime,endCreateTime));
    }
    
    /**
     *功能描述:商机转龙虎榜
     *@return:
     */
    @GetMapping("/businessChangeStatistics")
    public AjaxResult businessChangeStatistics(String beginCreateTime,String endCreateTime){
        List<Map<String,Object>> list = reportService.businessChangeStatistics(beginCreateTime,endCreateTime);
        return AjaxResult.success(list);
    }
}